<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script>
	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							/* frozenColumns : [ [ {
								field : 'ids',
								checkbox : true
							} ] ], */
							toolbar : [ {
								id : listDisplayEId + '_btn_edit',
								text : '导出excel',
								iconCls : 'icon-edit',
								handler : function() {
									var rows = $('#' + listDisplayEId)
											.datagrid('getRows');
									for (var i = 0; i < rows.length; i++) {
										var rowIndex = $('#' + listDisplayEId)
												.datagrid('getRowIndex',
														rows[i]['id']);
										$('#listDisplay').datagrid('endEdit',
												rowIndex);
									}
									var row = $('#' + listDisplayEId).datagrid(
											'getRows');
									if (row.length == 0) {
										$.messager
												.alert('提示', '无记录操作！', 'info');
										return;
									} else {
										var userList = new Array();
										var jsonFater;
										for (var i = 0; i < row.length; i++) {
											/* if ( row[i]['storeInState'] != 1 ){
												alert("订单已被确认");
												return false;
											}
											
											if ( row[i]['materNum'] == "" || !isNumberAndNoZero(row[i]['materNum'])  ){
												alert("材料"+row[i]['materId']+"，实际重量请填写数字！");
												return false;
											} */
											var materLevelText = formatFoodType(row[i]['materLevel']);
											var storeInWayTest = formatStoreInWay(row[i]['storeInWay']);
											var storeInStateTest = formatStoreInState(row[i]['storeInState']);
											var accountStateTest = formatAccountState(row[i]['accountState']);
											var jsonSun = "{id:'"
													+ row[i]['id']
													+ "',storeInId:'"
													+ row[i]['storeInId']
													+ "',storeHouseId:'"
													+ row[i]['storeHouseId']
													+ "',storeName:'"
													+ row[i]['storeName']
													+ "',custId:'"
													+ row[i]['custId']
													+ "',custName:'"
													+ row[i]['custName']
													+ "',supId:'"
													+ row[i]['supId']
													+ "',supName:'"
													+ row[i]['supName']
													+ "',materId:'"
													+ row[i]['materId']
													+ "',materName:'"
													+ row[i]['materName']
													+ "',materLevel:'"
													+ materLevelText
													+ "',storeInWay:'"
													+ storeInWayTest
													+ "',storeInState:'"
													+ storeInStateTest
													+ "',creatDate:'"
													+ row[i]['creatDate']
													+ "',materNum:'"
													+ row[i]['materNum']
													+ "',materValue:'"
													+ row[i]['materValue']
													+ "',accountState:'"
													+ accountStateTest
													+ "',accountDate:'"
													+ row[i]['accountDate']
													+ "'}";

											userList.push(jsonSun);
										}
										jsonFater = JSON.stringify(userList);
										var str = "json=" + jsonFater;
										document.getElementsByName("excelList")[0].value = jsonFater;

										excel();
									}
								}
							}

							],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							onClickRow : function(rowIndex) {
								$(".myrad").prop("checked", false);
								$(".myrad").eq(rowIndex).prop("checked", true);
								var row = $('#' + listDisplayEId).datagrid(
										'getRows');
								if (row[0]['storeInWay'] == "2") {
									$('#listDisplay').datagrid('beginEdit',
											rowIndex);
								}
							}
						});
	};
	$(document).ready(function() {
		initList('listDisplay');
	});

	function formatRadio(value, rowData, rowIndex) {
		return value = "<input type='radio' class='myrad'  name='radioStore' />";
	}

	function searchInfo() {
		if ($('#supId').combobox('getValue') == '') {
			alert("供货商不能为空");
		} else if ($('#creatDateEnd').datebox('getValue') == '') {
			alert("入库日期截止日不能为空");
		} else {

			$('#listDisplay').datagrid('load', {
				supId : $('#supId').combobox('getValue'),
				creatDateStart : $('#creatDateStart').datebox('getValue'),
				creatDateEnd : $('#creatDateEnd').datebox('getValue'),
				selectFlag : 1
			});
		}
	}
	$(function() {
		// 下拉框选择控件，下拉框的内容是动态查询数据库信息  
		$('#supId').combobox({
			url : "<c:url value='/store/pulldownSupId.do?space=0'/>",
			editable : false, //不可编辑状态  
			cache : false,
			valueField : 'supId',
			textField : 'supName',
		});
		/* $('#userId').combobox({   
		    url:"<c:url value='/store/pulldownUserId.do?space=1'/>",   
		    editable:false, //不可编辑状态  
		    cache: false,  
		    valueField:'userId',     
		    textField:'userName',  
		});     */
	});

	function excel() {
		$('#AddFoodForm').form('submit', {
			url : '<c:url value='/account/exportExcel.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
				return $('#AddFoodForm').form('validate');
			},
			success : function(data) {
				data = eval("(" + data + ")");
				if (data.success) {
					$.messager.alert("提示", "提交成功！", 'info', function() {
						window.close();
					});
				} else {
					$.messager.alert("提示", data.msg, 'warning');
				}
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});
	}
</script>
</head>
		<body>
			<table width="98%">
			<tr>
			<td>
				<form id="AddFoodForm" name="AddFoodForm" method="post">
				        <input class="easyui-validatebox" type="hidden" name="idList"  />
				        <input class="easyui-validatebox" type="hidden" name="excelList"  />
				        <input class="easyui-validatebox" type="hidden" name="footList"  />
                </form>
			</td>
			</tr>
		<tr>
		<td>
			<table id="listDisplay" title="结算详细列表" 
				iconCls="icon-list" singleSelect="false" idField="id"
				url="<c:url value="/account/findAccountsDetailed.do?accountId=${accountId }"/>" loadMsg="请稍候......"
				pagination="true" pageSize="100"
				pageList="[10,20,30,40,50,100]" sortName="storeInId"
				rownumbers="true" sortOrder="asc" showFooter="true">
			<thead>
				<tr>
					<th field="id" width="80"  sortable="true" editor="text" hidden = "true">
						ID
					</th>
					<th field="storeInId" width="80" formatter="formatDGField" sortable="true" >
						入库单号
					</th>
					 <th field="storeHouseId" width="60" formatter="formatDGField" sortable="true" editor="text">
						仓库号
					</th>	
 					<th field="storeName" width="80" formatter="formatDGField" sortable="true" editor="text">
						仓库名
					</th>		
					<th field="custId" width="100"  sortable="true" editor="text">
						仓库管理人id
					</th>	
					<th field="custName" width="80"  sortable="true" editor="text">
						仓库管理人名
					</th>	
					<th field="supId" width="60"  sortable="true" editor="text">
						供货商id
					</th>	
					<th field="supName" width="70"  sortable="true" editor="text">
						供货商名
					</th>	
				    <th field="materId" width="60" formatter="formatDGField" sortable="true" >
						材料id
					</th>	
 					<th field="materName" width="80" sortable="true" >
						材料名
					</th>		
					<th field="materLevel" width="50"  formatter="formatFoodType" sortable="true" >
						品级
					</th>
					<th field="storeInWay" width="80"  sortable="true"  formatter="formatStoreInWay">
						入库方式
					</th>
					<th field="storeInState" width="80"  sortable="true"  formatter="formatStoreInState">
						入库状态
					</th>
					<th field="creatDate" width="80"  sortable="true"  >
						入库日
					</th>
					<th field="materNum" width="150"  sortable="true" editor="text">
						实际入库数量(公斤/件/个)
					</th>
					<th field="materValue" width="60"  sortable="true" editor="text">
						结款价钱
					</th>
					<th field="accountState" width="60"  sortable="true" formatter="formatAccountState" >
						结款状态
					</th>
					<th field="accountDate" width="80"  sortable="true"  >
						结款日
					</th>
 				</tr>
			</thead>
			</table>
			</td>
			</tr>
		</table>
	</body>
</html>